/*
 * Copyright Eduardo Aponte 2013
 * aponteeduardo@gmail.com
 */
#include <eyelink.h>
#include "mex.h"
#include "utils.h"



INT16 _main( INT16 code  )
{
    return eyelink_close( code ); 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    double *status;
    int code;
    mwSize td[2] = {1,1};
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( isscalar( *prhs ) ){
        INT16 scalar;
        /* Returns the scalar, casts to int if necessary. Returns 0 if */
        /* input is complex. */
        if ( returnscalar( *prhs, &code ) != 1 )
        mexErrMsgTxt("Complex data is not supported.");                        
    } else {
        mexErrMsgTxt("send_msg should be a scalar.");                        
    }
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status  = mxGetPr(plhs[0]);    
    *status = (double ) _main( (INT16 ) code );

    return;
    
}


